<?php
namespace Admin\Model;

class AdModel extends SystemModel
{
    //调用配置文件中的数据库配置
    protected $connection = 'BLOCKER_DATABASE';
    protected $trueTableName = 'blocker_advertisement';

    public $affiliate_cache_key = 'aff_list';

    /**
     * 缓存网盟信息，每5分钟一次
     */
    public function setAffiliateCache()
    {
        $affs = [];
        $url = D('SysConfig')->getValue('AD_AFFILIATES_GET');
        $info = `curl -s --connect-timeout 5 '{$url}'`;
        if ($info = json_decode($info, true))
        {
            $data = $info['data'];
            foreach ($data as $k => $v)
            {
                $affs[$k] = $k;
            }

            $is_cache = S($this->affiliate_cache_key, json_encode($affs));
        }
        return ($is_cache==1) ? true : false;
    }

    /**
     * 获取网盟信息
     * @return array
     */
    public function getAffiliateCache()
    {
        return S($this->affiliate_cache_key) ? : [];
    }
	
}
